package cn.btks.backstagemanage.app.controller;

import cn.btks.backstagemanage.app.pojo.AppVersion;
import cn.btks.backstagemanage.app.service.AppVersionService;
import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author lijun
 * @Date 2021/4/9 15:33
 */
@RestController
@RequestMapping("api/v1.0/version")
@Api(tags = "版本控制模块")
@Validated
public class AppVersionController {

    @Autowired
    AppVersionService appVersionService;

    @GetMapping("/app/findAll")
    @ApiOperation(value = "查询所有版本信息", notes = "查询所有版本信息")
    @ApiImplicitParams({
    })
    public ResultState findAll() {
        List<AppVersion> appVersions = appVersionService.findAll();
        return appVersions != null ?
                new ResultState(StateInfo.FIND_OK.getCode(), StateInfo.FIND_OK.getMsg(), appVersions) :
                new ResultState(StateInfo.FIND_NULL.getCode(), StateInfo.FIND_NULL.getMsg());
    }

    @PostMapping(value = "/app/save", headers = "content-type=multipart/form-data")
    @ApiOperation(value = "新增版本控制信息", notes = "新增版本控制信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "appVersion", value = "版本号", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState save(AppVersion appVersion, @ApiParam(name = "文件", value = "multipartFile", required = true) MultipartFile multipartFile, HttpServletRequest request){
        return appVersionService.save(appVersion, multipartFile, request);
    }

    @PutMapping("/app/update")
    @ApiOperation(value = "修改版本控制信息", notes = "修改版本控制信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "唯一ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "query", name = "appVersion", value = "版本号", required = true, dataType = "string"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState update(@RequestBody AppVersion appVersion){
        return appVersionService.update(appVersion);
    }
}
